package com.budwk.app.sqfwV2.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.sqfw.models.Sqfw_formSummary_new;
import com.budwk.app.sqfw.vo.GenerateExcelUrlVO;
import com.budwk.app.sqfwDoc.dto.TemplateCodeUpdateDTO;
import com.budwk.app.sqfwV2.dto.dto.dayingRoad.DownExcelLedgerReqVo;
import com.budwk.app.sqfwV2.dto.dto.dayingRoad.DownFileTypesResVo;
import com.budwk.app.sqfwV2.service.entrepreneurShipHouse.EntrepreneurShipHouseService;
import com.budwk.starter.common.openapi.annotation.ApiDefinition;
import com.budwk.starter.common.openapi.annotation.ApiFormParams;
import com.budwk.starter.common.openapi.annotation.ApiOperation;
import com.budwk.starter.common.openapi.annotation.ApiResponses;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.log.annotation.SLog;
import lombok.extern.slf4j.Slf4j;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author yg
 * @since 2024/01/23
 */

@IocBean
@At("/platform/sqfwV2/entrepreneurShipHouse")
@ApiDefinition(tag = "创业实体入户")
@Slf4j
public class EntrepreneurShipHouseController {

    @Inject
    private EntrepreneurShipHouseService entrepreneurShipHouseService;

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "提交数据/生成PDF")
    @ApiFormParams(implementation = TemplateCodeUpdateDTO.class)
    @ApiResponses(implementation = GenerateExcelUrlVO.class)
    @SLog(tag = "大营路街道新增接口", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> submitData(@Param("..") TemplateCodeUpdateDTO dto) {
        log.info("EntrepreneurShipHouseController submitData param: {}", JSONObject.toJSONString(dto));
        entrepreneurShipHouseService.submitData(dto);
        return Result.success();
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "重新生成PDF")
    @SaCheckLogin
    public Result<?> reGeneratePDF(@Param("sqfwFlowId") String sqfwFlowId) {
        log.info("EntrepreneurShipHouseController reGeneratePDF sqfwFlowId: {}", sqfwFlowId);
        return entrepreneurShipHouseService.reGeneratePDF(sqfwFlowId);
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "下载Excle台账(按照编码下载)（支持批量下载）")
    @ApiResponses(implementation = GenerateExcelUrlVO.class)
    @SaCheckLogin
    public Result<?> downExcelLedger(@Param("..") DownExcelLedgerReqVo reqVo) {
        log.info("EntrepreneurShipHouseController downExcelLedger reqVo: {}", JSONObject.toJSONString(reqVo));
        reqVo.setAgainGenerate(true);
        return entrepreneurShipHouseService.downExcelLedger(reqVo);
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "根据输入的查询条件和内容查询列表信息")
    @ApiResponses(implementation = Sqfw_formSummary_new.class)
    @SaCheckLogin
    public Result<?> listByConditionKey(@Param("placeName") String placeName) {
        log.info("EntrepreneurShipHouseController listByConditionKey content: {}", placeName);
        return entrepreneurShipHouseService.listByConditionKey(placeName);
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "下载文件列表数据")
    @ApiResponses(implementation = DownFileTypesResVo.class)
    @SaCheckLogin
    public Result<List<DownFileTypesResVo>> listDownFileTypes(@Param("sqfwId") String sqfwId) {
        log.info("EntrepreneurShipHouseController listDownFileTypes start");
        return entrepreneurShipHouseService.listDownFileTypes(sqfwId);
    }

    @At
    @GET
    @ApiOperation(name = "下载word模板")
    public void downWordTemplate(HttpServletResponse response) {
        log.info("EntrepreneurShipHouseController downWordTemplate start");
        entrepreneurShipHouseService.downWordTemplate(response);
    }

}












